package com.isesol.ime.rest.api;

import com.github.pagehelper.*;
import com.isesol.api.rest.annoations.*;
import com.isesol.api.rest.model.base.*;
import com.isesol.arch.common.model.*;
import com.isesol.ime.Constant;
import com.isesol.ime.dal.model.dto.*;
import com.isesol.ime.rest.model.param.*;
import com.isesol.ime.service.*;
import org.springframework.stereotype.*;
import org.springframework.transaction.annotation.*;

import javax.annotation.*;

/**
 * 机床参数
 * <p>
 * <li> 机床参数新增
 * <li> 机床参数修改
 * <li> 机床参数删除
 * <li> 机床参数查找
 * </p>
 *
 * @author peter zhang
 * @author Wang Jun
 */
@Service
@RestServiceClass(url = "param")
public class ParamResource extends BusinessResources {

	@Resource
	ParamService paramService;

	@Transactional
	@RestServiceMethod(url = "create", requestType = MachineToolParamRequest.class)
	public void create(MachineToolParamRequest request) {

		LOGGER.info(Constant.MODEL_NAME_PARAM + "create接口调用,request={}", request);

		ParamDTO paramDTO = modelMapper.map(request, ParamDTO.class);

		paramService.create(paramDTO);

	}

	@Transactional
	@RestServiceMethod(url = "update", requestType = MachineToolParamRequest.class)
	public void update(MachineToolParamRequest request){

		LOGGER.info(Constant.MODEL_NAME_PARAM + "update接口调用,request={}", request);

		ParamDTO paramDTO = modelMapper.map(request, ParamDTO.class);

		paramService.update(paramDTO);

	}

	@Transactional
	@RestServiceMethod(url = "del", requestType = MachineToolParamRequest.class)
	public void del(MachineToolParamRequest request) {

		LOGGER.info(Constant.MODEL_NAME_PARAM + "del接口调用,request={}", request);

		ParamDTO paramDTO = modelMapper.map(request, ParamDTO.class);

		paramService.del(paramDTO);

	}

	@Transactional
	@RestServiceMethod(url = "find", requestType = MachineToolParamRequest.class)
	public PageInfo find(MachineToolParamRequest request) throws Exception {

		LOGGER.info(Constant.MODEL_NAME_PARAM + "find接口调用,request={}", request);

		ParamDTO paramDTO = modelMapper.map(request, ParamDTO.class);

		PageInfo pageInfo = paramService.find(paramDTO,
				request.getRestRequest().getPage(),
				request.getRestRequest().getRows());

		return pageInfo;

	}

	@Transactional
	@RestServiceMethod(url = "findById", requestType = MachineToolParamRequest.class)
	public com.isesol.ime.dal.model.dto.ParamDTO findById(MachineToolParamRequest request) throws Exception {

		LOGGER.info(Constant.MODEL_NAME_PARAM + "findById接口调用,request={}", request);

		ParamDTO paramDO = paramService.findById(request.getId());

		return paramDO;
	}

}